package com.jing.cloud.service.chat.adapter.handler.impl;

import com.jing.cloud.service.chat.adapter.MessageBean;
import com.jing.cloud.service.chat.bean.UserMessage;
import com.jing.cloud.service.chat.constant.ChatConstant;
import com.jing.cloud.service.chat.dao.UserMessageDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by 29017 on 2017/9/12.
 */
@Component
public class UpdateCursorHandler extends AbstractMessageHandler {


    @Autowired
    UserMessageDao userMessageDao;

    @Override
    public boolean handleMessage(MessageBean messageBean) {
        if (messageBean.getType() == ChatConstant.TYPE_SERVER) {
            if (messageBean.getType2() == ChatConstant.TYPE2_SERVER_RECEIVED) {
                UserMessage userMessage = new UserMessage();
                userMessage.setUserId(messageBean.getSender());
                userMessage.setMessageId(messageBean.getReceivedId());
                int type = messageBean.getDeviceType();
                switch (type) {
                    case 1:
                        userMessage.setPush1(ChatConstant.MESSAGE_PUSH_YES);
                        break;
                    case 2:
                        userMessage.setPush2(ChatConstant.MESSAGE_PUSH_YES);
                        break;
                    case 3:
                        userMessage.setPush3(ChatConstant.MESSAGE_PUSH_YES);
                        break;
                    case 4:
                        userMessage.setPush4(ChatConstant.MESSAGE_PUSH_YES);
                        break;
                    case 5:
                        userMessage.setPush5(ChatConstant.MESSAGE_PUSH_YES);
                        break;
                    case 6:
                        userMessage.setPush6(ChatConstant.MESSAGE_PUSH_YES);
                        break;
                }
                userMessageDao.updateForce(userMessage, 3);
            }
            return false;
        }
        return true;
    }

    @Override
    public int order() {
        return 1;
    }
}
